import { getDataByParameter, getObjetInfoByPid, saveObjetInfo, deleteObjetInfo } from '@/utils/baserequest'
// import storage from 'store'
import baseapi from '@/api/base'

const api = {
  dictserver: '/dict/',
  dictByDictCategory: '/dict/by/dictCategory/',
  dictCountByDictCategory: '/dict/countBy/dictCategory/',
  dictEntryByDictCode: '/dict/by/dictCode/'
  // orgInfo: '/'
}

export default api

// 查询字典列表
export function getDictByCategory (parameters, headers) {
  const allheaders = {
    appId: baseapi.huiwcore_app
  }
  if (headers.authOption) {
  } else {
    headers.authOption = '1'
  }
  if (parameters.pageSize) {
  } else {
    parameters.pageSize = 1000000
  }
  if (parameters.dictCategory === '字典分类') {
    parameters.dictCategory = 'dictCategory'
  }
  const url = baseapi.baseUrl + baseapi.huiwcore + api.dictByDictCategory
  return getDataByParameter(url, parameters, Object.assign(headers, allheaders))
}
// 查询字典数量
export function getDictCountByCategory (parameter, headers) {
  const allheaders = {
    appId: baseapi.huiwcore_app
  }
  if (parameter === '字典分类') {
    parameter = 'dictCategory'
  }
  const url = baseapi.baseUrl + baseapi.huiwcore + api.dictCountByDictCategory + parameter
  return getDataByParameter(url, parameter, Object.assign(headers, allheaders))
}

// 查询字典列表
export function getDictEntry (parameter, headers) {
  const allheaders = {
    appId: baseapi.huiwcore_app,
    authOption: '1'
  }
  const parameters = {
    dictCategory: parameter
  }
  const url = baseapi.baseUrl + baseapi.huiwcore + api.dictEntrysByDictCategory
  return getDataByParameter(url, parameters, Object.assign(headers, allheaders))
}

export function getDataInfoByPid (parameter, headers) {
  const allheaders = {
    appId: baseapi.huiwcore_app
  }
  const url = baseapi.baseUrl + baseapi.huiwcore + api.dictserver
  return getObjetInfoByPid(url, parameter, Object.assign(headers, allheaders))
}

// id == 0 add     post
// id != 0 update  put
export function saveInfo (parameter, headers) {
  const allheaders = {
    appId: baseapi.huiwcore_app
  }
  const url = baseapi.baseUrl + baseapi.huiwcore + api.dictserver
  return saveObjetInfo(url, parameter, Object.assign(headers, allheaders))
}

export function deleteByInfo (parameter, headers) {
  const allheaders = {
    appId: baseapi.huiwcore_app
  }
  const url = baseapi.baseUrl + baseapi.huiwcore + api.dictserver
  return deleteObjetInfo(url, parameter, Object.assign(headers, allheaders))
}
